﻿CREATE TABLE [audit].[TraceData] (
    [TraceName]         VARCHAR (255)  NOT NULL,
    [TextData]          NTEXT          NULL,
    [BinaryData]        IMAGE          NULL,
    [DatabaseID]        INT            NULL,
    [TransactionID]     BIGINT         NULL,
    [NTUserName]        NVARCHAR (128) NULL,
    [NTDomainName]      NVARCHAR (128) NULL,
    [HostName]          NVARCHAR (128) NULL,
    [ClientProcessID]   INT            NULL,
    [ApplicationName]   NVARCHAR (128) NULL,
    [LoginName]         NVARCHAR (128) NULL,
    [SPID]              INT            NULL,
    [Duration]          BIGINT         NULL,
    [StartTime]         DATETIME       NULL,
    [EndTime]           DATETIME       NULL,
    [Reads]             BIGINT         NULL,
    [Writes]            BIGINT         NULL,
    [CPU]               INT            NULL,
    [Permissions]       INT            NULL,
    [Severity]          INT            NULL,
    [EventSubClass]     INT            NULL,
    [ObjectID]          INT            NULL,
    [Success]           INT            NULL,
    [IndexID]           INT            NULL,
    [IntegerData]       INT            NULL,
    [ServerName]        NVARCHAR (128) NULL,
    [EventClass]        INT            NOT NULL,
    [ObjectType]        INT            NULL,
    [NestLevel]         INT            NULL,
    [State]             INT            NULL,
    [Error]             INT            NULL,
    [Mode]              INT            NULL,
    [Handle]            INT            NULL,
    [ObjectName]        NVARCHAR (128) NULL,
    [DatabaseName]      NVARCHAR (128) NULL,
    [FileName]          NVARCHAR (128) NULL,
    [OwnerName]         NVARCHAR (128) NULL,
    [RoleName]          NVARCHAR (128) NULL,
    [TargetUserName]    NVARCHAR (128) NULL,
    [DBUserName]        NVARCHAR (128) NULL,
    [LoginSid]          IMAGE          NULL,
    [TargetLoginName]   NVARCHAR (128) NULL,
    [TargetLoginSid]    IMAGE          NULL,
    [ColumnPermissions] INT            NULL,
    [LoadDate]          CHAR (8)       CONSTRAINT [DF_AuditTraceData_LoadDate] DEFAULT (CONVERT([char](8),getdate(),(112))) NOT NULL,
    [Seed]              INT            IDENTITY (1, 1) NOT NULL,
    CONSTRAINT [PK_AuditTraceData] PRIMARY KEY NONCLUSTERED ([Seed] ASC)
);


GO
CREATE CLUSTERED INDEX [CI_AuditTraceData_LoadDate]
    ON [audit].[TraceData]([LoadDate] ASC, [TraceName] ASC);

